package com.masterclient.app.modules.aftersale.adapter;

import android.text.TextUtils;

import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.masterclient.app.R;
import com.eoner.baselibrary.bean.aftersale.ReturnGoodsBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class PromotionNumAdapter extends BaseQuickAdapter<ReturnGoodsBean.DataBean.ShGiveProducts,BaseViewHolder> {
    public PromotionNumAdapter() {
        super(R.layout.item_aftersale_promotion);
    }

    @Override
    protected void convert(BaseViewHolder helper, ReturnGoodsBean.DataBean.ShGiveProducts item) {

        ViewTransformUtil.glideImageView(mContext, item.getSh_image(), helper.getView(R.id.item_promotion_img), new Transformation[]{new CenterCrop(),
                new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0)}, R.mipmap.defaults);
        helper.setText(R.id.item_promotion_title, item.getSh_name())
                .setText(R.id.item_promotion_sku, item.getSh_attribute_desc())
                .setText(R.id.item_promotion_num,"x"+item.getSh_qty_ordered())
                .setText(R.id.item_promotion_maxnum,"最多"+ item.getSh_qty_ordered() +"件")
                .setText(R.id.edit_num, TextUtils.isEmpty(item.getSh_refund_qty())?"0":item.getSh_refund_qty())
                .setGone(R.id.item_promotion_line, helper.getAdapterPosition() != getData().size()-1)
                .addOnClickListener(R.id.edit_num_plus)
                .addOnClickListener(R.id.edit_num_reduce);
        helper.getView(R.id.edit_num_reduce).setEnabled(!TextUtils.isEmpty(item.getSh_refund_qty())&&
                                                                Integer.parseInt(item.getSh_refund_qty())>0);
        helper.getView(R.id.edit_num_plus).setEnabled((TextUtils.isEmpty(item.getSh_refund_qty())&&Integer.parseInt(item.getSh_qty_ordered())>0)||
                                                              (!TextUtils.isEmpty(item.getSh_refund_qty())&&
                                                                Integer.parseInt(item.getSh_refund_qty())<Integer.parseInt(item.getSh_qty_ordered())));
    }
}
